package cn.four.hqServer.modules.hqtranuser.service.impl;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;

import cn.four.hqServer.common.entity.HqTranUser;
import cn.four.hqServer.modules.hqtranuser.mapper.ShzHqTranUserMapper;
@Service
public class ShzHqTranUserServiceImpl implements cn.four.hqServer.modules.hqtranuser.service.ShzIHqTranUserService{
	@Autowired
	private ShzHqTranUserMapper tranUserMapper;

	@Override
	public List<HqTranUser> getTransaction(String startTime, String endTime, String type,
			String payee,int pagestart,int pageend,String userid) {
		// 默认时间设置
		if (StringUtils.isBlank(startTime) && StringUtils.isBlank(endTime)) {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式
			Calendar cal = Calendar.getInstance(); // 得到日历
			Date now = new Date();
			cal.setTime(now);// 把当前时间赋给日历
			cal.set(Calendar.DATE, 1);
			Date time = cal.getTime();
			endTime = sdf.format(time);
			Calendar calendar = Calendar.getInstance(); // 得到日历
			calendar.setTime(now);// 把当前时间赋给日历
			calendar.add(Calendar.MONTH, -3); // 设置为前3月
			Date start = calendar.getTime();
			startTime = sdf.format(start);
		}
		List<HqTranUser> tranUserList = tranUserMapper.getTransaction(startTime, endTime, type, payee,pagestart,pageend, userid);
		return tranUserList;
	}

	public int getTransactionnum(String startTime, String endTime, String type, String payee,
			int pagestart,int pageend,String userid) {
		return tranUserMapper.getTransactionnum(startTime, endTime, type, payee,pagestart,pageend, userid);
	}
	
	public int insertTranUser(HqTranUser hqTranUser) {
		return tranUserMapper.insertTranUser(hqTranUser);
	}
}
